package com.beteng.su.betengsu.net;

/**
 * Created by chenzhimin on 2017/9/5.
 */


import org.reactivestreams.Subscriber;

import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

/**
 * 封装Subscriber
 *
 */
public abstract class RxSubscriber<T> implements Subscriber<T> {


    private String msg;

    @Override
    public void onError(Throwable e) {
        e.printStackTrace();

        if (e instanceof ServerException) {
            // 服务器异常
            msg = e.getMessage();
        }else if (e instanceof UnknownHostException) {
            msg = "没有网络...";
        } else if (e instanceof SocketTimeoutException) {
            // 超时
            msg = "超时...";
        }else{
            msg = "请求失败，请稍后重试...";
        }
        _onError(msg);
    }

    @Override
    public void onNext(T t) {
        _onNext(t);
    }

    public abstract void _onNext(T t);

    public abstract void _onError(String msg);
}